import request, { all } from '@/utils/request'

/**
 * 数据列表
 * @param params
 * @returns AxiosPromise
 */
export function paginate(params) {
  return request({
    url: '/bid/paginate',
    method: 'get',
    params: params
  })
}

/**
 * 用户信息
 * @returns {*}
 */
export function info(id) {
  return request({
    url: '/bid/info/' + id,
    method: 'get'
  })
}

/**
 * 保存数据
 * @param params
 * @param id
 * @returns AxiosPromise
 */
export function save(params, id = null) {
  return request({
    url: '/bid/' + (id ? 'update/' + id : 'store'),
    method: 'post',
    data: params
  })
}

/**
 * 删除数据
 * @param id
 * @returns AxiosPromise
 */
export function destroy(id) {
  return request({
    url: '/bid/destroy/' + id,
    method: 'delete'
  })
}

/**
 * 竞标
 * @param params
 * @param id
 * @returns AxiosPromise
 */
export function storeGoods(params) {
  return request({
    url: '/bid/goods/store',
    method: 'post',
    data: params
  })
}

/**
 * 竞标
 * @param params
 * @param id
 * @returns AxiosPromise
 */
export function getBidGoodsPaginate(params) {
  return request({
    url: '/bid/goods/paginate',
    method: 'get',
    params: params
  })
}

/**
 * 竞标
 * @param params
 * @param id
 * @returns AxiosPromise
 */
export function getBidGoodsSummary(params) {
  return request({
    url: '/bid/goods/summary',
    method: 'get',
    params: params
  })
}

/**
 * 竞标
 * @param params
 * @param id
 * @returns AxiosPromise
 */
export function getBidGoodsSummaryUser(params) {
  return request({
    url: '/bid/goods/summary/user',
    method: 'get',
    params: params
  })
}

/**
 * 商品列表初始数据
 * @param params
 * @param callback
 */
export function initialSummary(params, callback) {
  const url = [
    // request.get('/bid/goods/summary', { params }),
    request.get('/supplier/paginate', { params: { status: 1, is_list: 1 }}),
    request.get('/bid/paginate', { params: { is_list: 1 }})
  ]
  all(url, function(res) {
    if (res !== false) {
      callback(res)
    }
  })
}

/**
 * 商品列表初始数据
 * @param params
 * @param callback
 */
export function initialGoods(params, callback) {
  const url = [
    // request.get('/bid/goods/summary/user', { params }),
    request.get('/supplier/paginate', { params: { status: 1, is_list: 1 }}),
    request.get('/bid/paginate', { params: { is_list: 1 }})
  ]
  all(url, function(res) {
    if (res !== false) {
      callback(res)
    }
  })
}
